import React, { useState, useEffect } from "react";
import {
  SearchOutlined,
  PlusCircleOutlined,
  DiffOutlined,
  ScissorOutlined,
} from "@ant-design/icons";
import { Form, Input, Space, Breadcrumb, Button, Row, Col, Table } from "antd";
import axios from "axios";

const BingRenRuYuanXinXi = (props) => {
  // 请求数据
  const [page, setpage] = useState(1);
  const [data, setdata] = useState([]);
  const getData = () => {
    axios("/ruYuanBingRenJiBenZiLiaoDengJi/chaXunAll", {
      method: "GET",
      // headers: { "content-Type": "application/json" },
      params: {
        page: 1,
      },
    })
      .then((response) => {
        // console.log(response);

        if (response.data.code == 200) {
          for (let i = 0; i < response.data.list.length; i++) {
            response.data.list[i].key = i + 1;
          }
          setdata(response.data.list);
          // console.log(data);
          // settotal(response.data.data.length)
        } else {
          console.log(response.msg);
        }
      })
      .catch((error) => {
        console.log(error);
      });
  };
  useEffect(() => {
    getData();
  }, []);

  const columns = [
    {
      title: "住院号",
      dataIndex: "zhuYuanHao",
      key: "zhuYuanHao",
    },
    {
      title: "姓名",
      dataIndex: "xingMing",
      key: "xingMing",
    },
    {
      title: "性别",
      dataIndex: "xingBie",
      key: "xingBie",
    },
    {
      title: "出生日期",
      dataIndex: "chuShengRiQi",
      key: "chuShengRiQi",
    },
    {
      title: "科室",
      dataIndex: "keBie",
      key: "keBie",
    },
    {
      title: "入院时间",
      dataIndex: "ruYuanRiQi",
      key: "ruYuanRiQi",
    },
    {
      title: "身份证号",
      dataIndex: "shenFenZhengHao",
      key: "shenFenZhengHao",
    },
    {
      title: "联系人电话",
      dataIndex: "lianXiRenDianHua",
      key: "lianXiRenDianHua",
    },
    {
      title: "疾病类别",
      dataIndex: "icd9BianMa",
      key: "icd9BianMa",
    },

    {
      title: "操作",
      render: (record) => (
        <Space>
          <Button
            size="small"
            type="default"
            onClick={() => {
              Ckan(record);
            }}
          >
            <span>
              <DiffOutlined />
            </span>
            查看{" "}
          </Button>{" "}
          <Button
            style={{ color: "red" }}
            size="small"
            type="default"
            onClick={xGai}
          >
            <span>
              <ScissorOutlined />
            </span>
            修改{" "}
          </Button>{" "}
        </Space>
      ),
      key: "handle",
    },
  ];

  //修改
  const xGai = () => {
    props.history.push("xzbr");
  };
  //新增
  const xz = () => {
    props.history.push("xzbr");
  };
  //查看
  const Ckan = (record) => {
    // sessionStorage.setItem(record); //短时间数据储存
    sessionStorage.setItem("record", JSON.stringify(record));
    props.history.push("psi");
  };
  //查询
  const onFinish = (val) => {
    console.log(val);
    // dataSource
    // 定义一个新的空数组装满足条件的数据
    let newData = [];
    data.forEach((item) => {
      if (item.name.indexOf(val.input.xingMing) != -1) {
        newData.push(item);
      }
    });
    setdata = newData;
    data = newData;
  };
  return (
    <div>
      <Breadcrumb
        style={{
          marginBottom: 24,
        }}
      >
        <Breadcrumb.Item> 入院管理 </Breadcrumb.Item>{" "}
        <Breadcrumb.Item> 病人入院信息 </Breadcrumb.Item>{" "}
      </Breadcrumb>{" "}
      <div
        className="site-layout-background"
        style={{
          padding: 24,
          margin: 12,
          minHeight: 60,
        }}
      >
        <Form layout="inline" onFinish={onFinish}>
          <Form.Item label="姓名" name={["input", "xingming"]}>
            <Input
              type="name"
              value={data.name}
              placeholder="请输入姓名"
            ></Input>{" "}
          </Form.Item>
          <Form.Item label="住院号" name={["input", "zhuyuanhao"]}>
            <Input
              type="zhuyuanhao"
              value={data.zhuyuanhao}
              placeholder="请输入住院号"
            ></Input>{" "}
          </Form.Item>
          <Form.Item label="科室" name={["input", "keBie"]}>
            <Input
              type="keBie"
              value={data.keBie}
              placeholder="请输入查找的科室"
            ></Input>{" "}
          </Form.Item>
          <Row>
            <Col>
              <Button
                htmlType="submit"
                style={{
                  color: "white",
                  backgroundColor: "#67C23A",
                  border: "none",
                }}
              >
                <span>
                  <SearchOutlined />
                </span>
                查询{" "}
              </Button>{" "}
              <Button
                type="primary"
                style={{
                  marginLeft: 30,
                }}
                onClick={xz}
              >
                <span>
                  <PlusCircleOutlined />
                </span>
                新增{" "}
              </Button>{" "}
            </Col>{" "}
          </Row>{" "}
        </Form>{" "}
      </div>{" "}
      <div
        className="site-layout-background"
        style={{
          padding: 24,
          margin: 12,
          minHeight: 300,
        }}
      >
        <Table dataSource={data} columns={columns} />{" "}
      </div>{" "}
    </div>
  );
};
export default BingRenRuYuanXinXi;
